<?php

// header("Content-Type: text/html; Charset = UTF-8");

// set runtime env
defined('APP_ENV')      or define('APP_ENV'  , 'prod');

// 正式环境 关闭调试、错误报告
if (APP_ENV == 'prod')
{
    defined('APP_DEBUG')    or define('APP_DEBUG', false);
    defined('APP_TRACE')    or define('APP_TRACE', false);
    error_reporting(0);

// 非正式环境只允许本地访问
} else {
    $allowIp = ['127.0.0.1', 'fe80::1', '::1'];

    if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || !(in_array(@$_SERVER['REMOTE_ADDR'], $allowIp ) || php_sapi_name() === 'cli-server')
    ) {
        header('HTTP/1.0 403 Forbidden');
        exit("<h1>403 Forbidden</h1>\n:( Sorry! Informal environment allow only local access,You are not allowed to access this file.");
    }

    defined('APP_DEBUG')    or define('APP_DEBUG', true);
    defined('APP_TRACE')    or define('APP_TRACE', true);
    error_reporting(E_ALL);
}

require __DIR__ . '/define.php';

$loader = require __DIR__ . '/newLoader/autoload.php';

// service configurator
$configurator = new ulue\web\Configurator();

/* ===============创建容器,注册基本服务=============== */
$container = $configurator->registerService()->getDi();

$container->share('loader', $loader);

return $container;

